//
//  PostalTrackerSystemMenuItemView.m
//  PostalTracker
//
//  Created by Aleksandr Batsuev on 1/31/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "PostalTrackerSystemMenuItemView.h"
#import "PostalTrackerAppDelegate.h"

@implementation PostalTrackerSystemMenuItemView

- (id)initWithFrame:(NSRect)frameRect
{
	NSBundle *bundle = [NSBundle bundleForClass:[controller class]];
	NSString *path = [bundle pathForResource:@"18x18_bw" ofType:@"png"];
	iconBW = [[NSImage alloc] initWithContentsOfFile:path];
	
	path = [bundle pathForResource:@"18x18" ofType:@"png"];
	icon = [[NSImage alloc] initWithContentsOfFile:path];
	
	currentIcon = iconBW;

	[super initWithFrame:frameRect];
	return self;
}

- (void)hideContent
{
	clicked = false;
	[self setNeedsDisplay:YES];
	[self drawRect:[self frame]];
} 

- (void)setController:(PostalTrackerAppDelegate*) value 
{
	controller = value;
}

- (void)drawRect:(NSRect)rect {
	
    if ([controller contentWindowVisible]) {
        [[NSColor selectedMenuItemColor] set];
        NSRectFill(rect);
    }
	
	[currentIcon drawInRect:[self frame] fromRect:NSMakeRect(0, 0, 19, 19) operation:NSCompositeSourceOver fraction:1];
}

- (void)mouseDown:(NSEvent *)event
{
    NSRect frame = [[self window] frame];
    NSPoint pt = NSMakePoint(NSMidX(frame), NSMinY(frame));
    [controller toggleAttachedWindowAtPoint:pt];
    clicked = !clicked;
    [self setNeedsDisplay:YES];
}

- (void)showUpdated
{
	currentIcon = icon;
	[self setNeedsDisplay:YES];
	[self drawRect:[self frame]];
}

- (void)showNoNews
{
	currentIcon = iconBW;
	[self setNeedsDisplay:YES];
	[self drawRect:[self frame]];
}



@end
